class PID:
    def __init__(self, kp, ki, kd):
        self._pre_err = 0
        self._int_err = 0
        self._kp = kp
        self._ki = ki
        self._kd = kd

    def algorithm(self, err):
        pout = err * self._kp
        self._int_err += err
        iout = self._int_err * self._ki
        der_error = err - self._pre_err
        dout = der_error * self._kd
        out = pout + iout + dout
        return out
